package com.youmingxing.adpter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.youmingxing.R;
import com.youmingxing.bean.TopicInfo;

import java.util.List;

/**
 * Author : 李雄
 * Date : 2016/4/6 0006
 * Email: LiXiong0713@163.com
 * Description :
 *  在#活动中，选择话题的适配器
 */
public class TopicAdapter extends BaseAdapter {

    private Activity mActivity;
    private List<TopicInfo> mTopicInfos;

    public TopicAdapter(Context context,List<TopicInfo> topicInfos) {
        this.mActivity = (Activity) context;
        this.mTopicInfos = topicInfos;
    }

    @Override
    public int getCount() {
        return mTopicInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return mTopicInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(mActivity, R.layout.item_lv_topic,null);
            holder.mImageView = (ImageView) convertView.findViewById(R.id.iv_topic);
            holder.title = (TextView) convertView.findViewById(R.id.tv_topic_title);
            holder.desc = (TextView) convertView.findViewById(R.id.tv_topic_desc);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        TopicInfo topicInfo = mTopicInfos.get(position);
        Glide.with(mActivity).load(topicInfo.getImg()).placeholder(R
                .drawable.default_16_9).animate(R.anim.abc_fade_in).into(holder.mImageView);
        holder.title.setText(topicInfo.getTitle());
        holder.desc.setText(topicInfo.getDescription());
        return  convertView;
    }


    private class ViewHolder {
        public ImageView mImageView;
        public TextView title;
        public TextView desc;
    }
}
